//*********************************************************************
//		Copyright (c) 2003 - 2008 Microsoft Corporation.
//      This code is provided under Microsoft Public License, which can be found at
//      http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx 
//
// @File: Target.cs
//
// Purpose: Status-reporting infrastructure
//
//
//
// Notes: 
//
//
//	
// History: 
//     @Version: V2.1
//
//     07/17/08 PGV 2.1.001.0 Starting V2.1 (based on 2.0.030.0 code)
//
//
// @EndHeader@
//*********************************************************************

using System;

namespace H2V2
{
	public enum StatusEventType
	{
		NOTHING = 0,
		STATUS,
		INFO,
		WARNING,
		ERROR,
		EXCEPTION,
		DEBUG,
		STACK_TRACE
	}

	public class StatusChangeEventArgs : EventArgs 
	{
		public string m_text;
		public StatusEventType m_type = StatusEventType.STATUS;
		public bool m_IsException = false;
		public Exception m_exception;

		public StatusChangeEventArgs (string a_text) {m_text = a_text;}
		public StatusChangeEventArgs (string a_text, StatusEventType a_type) 
		{
			m_text = a_text;
			m_type = a_type;
		}
		public StatusChangeEventArgs (Exception a_ex)
		{
			m_IsException = true;
			m_exception = a_ex;
			m_type = StatusEventType.EXCEPTION;
		}
	}

    public class StatusObject
	{
		public delegate void StatusChangeEventHandler (object source, StatusChangeEventArgs args);
		public event StatusChangeEventHandler OnStatusChangeHandler;
		
		protected void ChangeStatus (string a_str, StatusEventType a_type)
		{
			OnStatusChangeHandler (this, new StatusChangeEventArgs (a_str, a_type));
		}

		protected void ChangeStatus (string a_str)
		{
			ChangeStatus (a_str, StatusEventType.STATUS);
		}

		protected void ChangeStatus (Exception a_ex)
		{
			OnStatusChangeHandler (this, new StatusChangeEventArgs (a_ex));
		}

		public void OnStatusChange (object source, StatusChangeEventArgs args)
		{	
			if (args.m_IsException) 
			{
				ChangeStatus (args.m_exception);
			}
			else
			{
				ChangeStatus (args.m_text, args.m_type);
			}
		}
	}
}
